<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>后台管理系统</title>
	    <meta name="author" content="BaiYY"/>
	    <meta charset="utf-8">
	    <meta http-equiv="X-UA-Compatible" content="IE=edge">
	    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
	    <meta name="renderer" content="webkit">
	    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/bootstrap.min.css"/>
	    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/Font/css/font-awesome.min.css"/>
	    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/index.css"/>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/jquery.js"></script>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/bootstrap.min.js"></script>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/index.js"></script>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/time.js"></script>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/bootstrap-paginator.js"></script>
	</head>
	<body>
		<div class="right-sidebar" style="max-width: 1200px;">
			<ul class="nav nav-tabs" style="margin-bottom: 16px" role="tablist">
				<li role="presentation" class="active"><a href="myRebateList.html">后台返利</a></li>
				<li role="presentation" id="onLineRebate"><a href="onLineRebate.html">{:L(GAME_ONLINE_REBATE)}</a></li>
			</ul>
			<div class="admin_tab_cont" style="display:block;" id="tab1">
				<section class="table-responsive">
					<table class="table table-bordered">
						<thead>
							<tr id="head">
								<th>流水号</th>
								<th>消费者</th>
								<th>商品ID</th>
								<th>商品价格</th>
								<th>返利比例</th>
								<th>返利金额</th>
								<th>返利时间</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody id="dataList"></tbody>
					</table>
				</section>
				<div style="width: 100%;">
					<nav aria-label="Page navigation" >
						<div id="example">
							<ul id="pageShow" class="pull-left"></ul>
						</div>
					</nav>
				</div>
			</div>
			<div id="bg-models">
				<div id="bg-contents">
					<i class="glyphicon glyphicon-remove" id="btn-closed"></i>
					<div class="title_dialog">系统提示！</div>
					<div class="discription_dialog">确定要删除这条数据吗？</div>
					<div class="footer_dialog">
						<button class="btn btn-primary" id="btn-ok">确定</button>
						<button class="btn btn-primary" id="btn-off">取消</button>
					</div>
				</div>
			</div>
		</div>
		<script type="text/javascript">
			$(function () {
                var onLineRebate = $.trim($("#onLineRebate").text());

                if(onLineRebate == '' || onLineRebate == 'GAME_ONLINE_REBATE') {
                    $("#onLineRebate").hide();
                }

				showpage()
				function showpage(pages){
					var page=pages?pages:1;
					$.ajax({
						type:"get",
						dataType:"json",
						url:"{:U('Admin/Main/myRebateListPage')}",
						data:{page:page},
						success:function(data){
	//						console.log(data);
							var str = '';
							if(data != 'nodata') {
								for(var i=0;i<data.data.length;i++) {
									var time = getLocalTime(data.data[i].add_time);
									str +="<tr><td class='id'>"+data.data[i].buy_id+"</td><td>"+data.data[i].buy_user_id+"</td><td>"+data.data[i].goods_id+"</td><td>"+data.data[i].amount+"</td><td>"+data.data[i].rebate_scale+"</td><td>"+data.data[i].rebate+"</td><td>"+time+"</td><td><button class='btn btn-primary btn-sm' onclick='onClick(this)'> 删除 </button> </td></tr>";
								}
								$("#dataList").html(str);
							}else{
								$("#dataList").html("没有任何数据");
							}

							var options = {
								currentPage: data.page,    //当前页，可以请求到数据再配置
								totalPages: data.pageSize,    //总共多少页，可以请求到数据再配置
								size:"normal",
								bootstrapMajorVersion: 3,//bootstrap版本
								alignment: "center", //对齐方式
								numberOfPages:2,    //每一波显示几个
								itemTexts: function (type, page, current) {
									switch (type) {
										case "first": return "首页";
										case "prev": return "上一页";
										case "next": return "下一页";
										case "last": return "末页";
										case "page": return page;
									}
								},
								// 选择那页点击事件
								onPageClicked:function(event,originalEvent,type,page){
		//							console.log(page)//可以获取当前页，拿这个值去发请求即可
									showpage(page);
								},
							}

							$('#pageShow').bootstrapPaginator(options);
						}
					});
				}
            });
				function onClick(This) {
					var id=$(This).closest("tr").find("td.id").text();
					$("#bg-models").fadeIn();
					$("#btn-ok").on("click",function () {
                        $.ajax({
                            type:"post",
                            url: "{:U('Admin/Main/recoderDel')}?act=rebate&id="+id,
                            success:function(data) {
                                if(data == 'success') {
                                    window.location.href="{:U('Admin/Main/rebateList')}";
                                }else if(data == 'error') {
                                    window.location.href="{:U('Admin/Main/rebateList')}";
                                }
                            }
                        });
                    });
                    $("#btn-closed").on("click",function () {
                        $("#bg-models").hide();
                    });
                    $("#btn-off").on("click",function () {
                        $("#bg-models").hide();
                    });
				}
		</script>
	</body>
</html>